package ru.ifmo.filemanager.filesystem.keylistener;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;

import ru.ifmo.filemanager.filesystem.FileSystem;
import ru.ifmo.filemanager.filesystem.interfaces.FileSystemObject;
import ru.ifmo.filemanager.filesystem.interfaces.PluginKeyListener;

public class FileKeyListener implements KeyListener {

	private final Map<KeyRequest,PluginKeyListener> actionMap = new HashMap<KeyRequest,PluginKeyListener>();
	
	public void AddPluginListener(PluginKeyListener listener, KeyRequest request )
	{
		actionMap.put(request, listener);
	}
	
	@Override
	public void keyPressed(KeyEvent arg0) {
		
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
			FileSystemObject object = FileSystem.getSelectedItem();
			
			if( object == null )
				return;
			
			KeyRequest requset = new KeyRequest(object.type(), arg0.keyCode);
			
			if( !actionMap.containsKey(requset)) {
				return;
			}
			
			PluginKeyListener listener = actionMap.get(requset);
			
			listener.keyClicked(object);
	}
}
